package com.ch02.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * @ClassName MvcConfig
 * @Description Mvc的配置类
 * @Author Kx
 * @Date 2025/5/9 11:22
 * @Version 1.0
 */
// 标识为配置类
@Configuration
// 启用Mvc注解
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        // 实例化内部资源视图解析器
        InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();

        // 设置前缀
        internalResourceViewResolver.setPrefix("/WEB-INF/jsp/");

        // 设置后缀
        internalResourceViewResolver.setSuffix(".jsp");

        // 注册视图解析器
        registry.viewResolver(internalResourceViewResolver);
    }
}
